package com.mezz.bones.framework.gateway.resolver;

import com.mezz.bones.framework.gateway.constant.GatewayConstants;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

@Component
public class DefaultRouteVersionResolver implements RouteVersionResolver {
    private static final String DEFAULT_VERSION = "1.0.0";

    @Override
    public String resolve(ServerWebExchange exchange) {
        String version = exchange.getRequest().getHeaders().getFirst(GatewayConstants.X_ROUTE_VERSION_HEADER_KEY);
        return (version != null && !version.isBlank()) ? version : DEFAULT_VERSION;
    }
}